﻿package mortal.game.view.tianDiRank.data
{
    import com.gengine.resource.*;

    public class TianDiRankConfig extends Object
    {
        public var copyCfg:Object;
        public var bossCfg:Array;
        public var copyArr:Array;
        private static var _instance:TianDiRankConfig;

        public function TianDiRankConfig()
        {
            this.copyCfg = {};
            this.copyArr = [];
            var _loc_1:* = ConfigManager.instance.getJSONByFileName("t_placard_copy_boss_list.json");
            this.writeBoss(_loc_1);
            _loc_1 = ConfigManager.instance.getJSONByFileName("t_placard_copy_config.json");
            this.writeCopy(_loc_1);
            return;
        }// end function

        private function writeBoss(param1:Object) : void
        {
            this.bossCfg = param1 as Array;
            return;
        }// end function

        private function writeCopy(param1:Object) : void
        {
            var _loc_4:Object = null;
            var _loc_2:Array = [];
            var _loc_3:Array = [];
            for each (_loc_4 in param1)
            {
                
                this.copyCfg[_loc_4.id] = _loc_4;
                if (_loc_4.placardType == 2)
                {
                    _loc_2.push(_loc_4);
                    continue;
                }
                _loc_3.push(_loc_4);
            }
            _loc_2.sort(this.sortCopy);
            _loc_3.sort(this.sortCopy);
            this.copyArr[0] = _loc_2;
            this.copyArr[1] = _loc_3;
            return;
        }// end function

        public function getPosById(param1:int) : int
        {
            var _loc_3:Object = null;
            var _loc_4:Array = null;
            var _loc_6:Object = null;
            var _loc_2:int = -1;
            _loc_3 = this.copyCfg[param1];
            if (_loc_3 == null)
            {
                return _loc_2;
            }
            if (_loc_3.placardType == 2)
            {
                _loc_4 = this.copyArr[0];
            }
            else
            {
                _loc_4 = this.copyArr[1];
            }
            var _loc_5:int = 0;
            while (_loc_5 < _loc_4.length)
            {
                
                _loc_6 = _loc_4[_loc_5];
                if (_loc_6.id == param1)
                {
                    return _loc_5;
                }
                _loc_5++;
            }
            return _loc_2;
        }// end function

        public function isDiById(param1:int) : Boolean
        {
            var _loc_3:Object = null;
            var _loc_2:Boolean = false;
            _loc_3 = this.copyCfg[param1];
            if (_loc_3 == null)
            {
                return _loc_2;
            }
            if (_loc_3.placardType == 2)
            {
                return true;
            }
            return false;
        }// end function

        public function getCopyById(param1:int) : Object
        {
            return this.copyCfg[param1];
        }// end function

        private function sortCopy(param1:Object, param2:Object) : int
        {
            if (param1.jobLevel < param2.jobLevel)
            {
                return -1;
            }
            if (param1.jobLevel > param2.jobLevel)
            {
                return 1;
            }
            if (param1.jobPosition < param2.jobPosition)
            {
                return -1;
            }
            if (param1.jobLevel > param2.jobLevel)
            {
                return 1;
            }
            return 0;
        }// end function

        public static function get instance() : TianDiRankConfig
        {
            if (_instance == null)
            {
                _instance = new TianDiRankConfig;
            }
            return _instance;
        }// end function

    }
}
